<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>普惠商城-个人中心-推广中心-申请推广师</title>
	<link rel="stylesheet" th:href="@{/css/common.css}">
	<!-- 个人中心通用样式personal.css -->
	<link rel="stylesheet" th:href="@{/css/personal.css}">
	<link rel="stylesheet" th:href="@{/css/personal-order-Line.css}">
	<link rel="stylesheet" th:href="@{/css/paging.css}">
	<style>
		.pwdhidden{
			display: none;
		}
		.allotBox {
		    padding: 10px 25px 25px 25px;
		}
		.showMaxImgClas{
			width: 100%;
			height: 100%;
		}
	</style>
</head>
<body>
	
	<!-- 顶部导航条开始 -->
	<div  th:include="personal/personalhead::order-personalhead-nav"></div>
	<!-- 顶部导航条结束 -->
	<!-- 顶部搜索栏部分开始 -->
	<div  th:include="personal/personalsearch::order-personalsearch-nav"></div>
	<!--个人中心中间主体框架  -->
	<div class="centerbody personal_middle">
		<!-- 左侧通用导航栏 -->
		<div class="personal_middle_nav" th:include="commonfragment::order-left-menu-nav"></div>
		<div class="centerbody personal_middle_main">
			<div class="personal_middle_main_tit">
				<span>推广中心</span>><span>申请推广师</span>
			</div>
			<!-- 订单tab标签 -->
			<div data-role="page">
        		<div data-role = "content-floud">
					<div class="publicBox allotBox">
						<!-- authInfo -->
						<p th:if="${authInfo != null}" class="allotType textright"><label for="">审核状态：</label>
							<span th:if="${authInfo.status == 1}" style="color: red">待审核</span>
							<span th:if="${authInfo.status == 2}" style="color: red">审核通过</span>
							<span th:if="${authInfo.status == 3}" style="color: red">审核未通过</span>
						</p>
						<p class="allotType textright"><label for="">企业类型：</label>
							<span><input type="radio" name="radio" value="2" checked>本地电商</span>
							<span><input type="radio" name="radio" value="1">新业态</span>
						</p>
						<p class="allotType textright">
							<label for="">账号：</label>
								<input type="text" name="" placeholder="请输入帐户" id="user_name" th:if="${authInfo != null}" th:value="${authInfo.account}">
								<input type="text" name="" placeholder="请输入帐户" id="user_name" th:if="${authInfo == null}">
						</p>
						<p class="allotType textright pwdhidden" th:if="${authInfo == null || authInfo.status == 3}">
							<label for="">密码：</label>
							<input type="password" name="" placeholder="请输入密码" id="user_pwd">
						</p>
						<div class="allotType textright" th:if="${authInfo == null || authInfo.status == 3}">
							<label for="">推广师证件：</label>
							<span class="alloFile">
								<span id="select_imgurl" class="fileUrl"></span>
								<i>浏览</i>
								<form method="post" enctype="multipart/form-data" id = "uploadImg">
									<input type="file" name="uploadImg" onchange="promotionauth.doUpload('uploadImg','imgfileUrl')" id="imgfileUrl" accept="image/jpg,image/png,image/gif,image/bmp,image/jpeg"/>
									<input type="hidden" name="module" value="promotion"/>
								</form>
							</span>
						</div>
						<div class="allotImg">
							<p class="itemImg">
								<img th:if="${authInfo != null }" th:src="${authInfo.image}" alt="" id="img_url">
								<img th:if="${authInfo == null }" src="" alt="" id="img_url">
							</p>
							<input type="hidden" th:if="${authInfo != null}" th:value="${authInfo.accountType}" id="sureAccountType"/>
							<input type="hidden" th:if="${authInfo != null}" th:value="${authInfo.status}" id="auth_status"/>
							<span th:if="${authInfo == null || authInfo.status == 3}">
								<input type="button" value="申请" id="authSubBtn">
							</span>
						</div>
						<input type="hidden" id="result_img_url"/>
						<input type="hidden" id="token_id" th:value="${token}"/>
					</div><!--分润金额-->
				</div>
   			 </div>
			<!-- 全部订单 -->
			
		</div>
		<div style="clear:both;"></div>
	</div>
	
	<!-- 页面底部 -->
	<div th:include="footer::footer"></div>
</body>
<script type="text/javascript" th:src="@{/js/jquery.page.js}"></script>
<script th:inline="javascript">
$(function(){
    $('.personal_box_tit_link span').eq(2).css('display','block');
	$(".box1 input:checked").parent().parent().addClass("selected");
	$(".box1 input").change(function(){
        $(".box1 input:checked").parent().parent().addClass("selected").siblings().removeClass("selected");
    });
	$('input.paybutton').eq(0).addClass('choose');

	$('input.paybutton').hover(function(){
		$(this).addClass('choose');
		$(this).siblings().removeClass('choose');
	},function(){
		$(this).removeClass('choose');
	})
	$('.cancel_small').click(function(){
		$('.shadow').css('display','none');
		$('.login_box_2').css('display','none');
	})

	$('.add_info').click(function(){
		$('.shadow').css('display','block');
		$('.login_box_2').css('display','block');
	})
	$('.shadow').css('height',$(window).height());
		$('.login_box_2').css('top',($(window).height()-$('.login_box_2').height())/2);
		$('.login_box_2').css('left',($(window).width()-$('.login_box_2').width())/2);
	$(window).resize(function(){
		$('.shadow').css('height',$(window).height());
		$('.login_box_2').css('top',($(window).height()-$('.login_box_2').height())/2);
		$('.login_box_2').css('left',($(window).width()-$('.login_box_2').width())/2);
	})
	$("#hear li").click(function(){
		$(this).css({
			 borderBottom: "2px solid red",
			 height:"43px"
		}).siblings().css({
			borderBottom: "none",
			height:"45px"
		});
	});
	/*分页*/
    $(".tcdPageCode").createPage({
        pageCount:100,
        current:1,
        backFn:function(p){
            //console.log(p);
        }
    });
	$("#hear li").click(function(){
		$(this).addClass("action").siblings().removeClass("action");
		var index = $(this).index();
		$("#contentop li").eq(index).css("display","block").siblings().css("display","none");
	});
})
$(function(){
	promotionauth.bingClosetipsIndex();
	var acctype = $("#sureAccountType").val();
	if(acctype){
		promotionauth.selectRedioByType(acctype);
		var status = $("#auth_status").val();
		if(status != 3){
			$(".textright :radio").attr("disabled",true);
			$("#user_name").attr("disabled",true);
		}
	}
	var type  = $("input[type='radio']:checked").val();
	promotionauth.selectType(type);
	promotionauth.redioSelct();
	var fileUrl = $("#img_url").attr("src");
	$("#result_img_url").val(fileUrl);
	$("#select_imgurl").html(fileUrl);
})
// tips 标记
var tipsIndex;
// 申请推广师
var promotionauth = {
	// 判断图片类型
	checkImgType : function(file){
		if (file == null || file == "") {
			promotionauth.msg("请选择你要上传的图片");
            return false;
        }
        var array = [".jpg",".jpeg",".gif",".bmp",".png"];
        var extName = file.substring(file.lastIndexOf(".")).toLowerCase();//（把路径中的所有字母全部转换为小写）
        if ($.inArray(extName, array) == -1) {
            ErrMsg = "暂不支持该图片格式,请上传 " + '[jpg,jpeg,gif,bmp,png]' + " 类型的文件，当前文件类型为" + extName;
            promotionauth.msg(ErrMsg);
            return false;
        }
        return true;
	},// 提示消息
	msg : function(val){
		layer.msg(val);
	},
	alert : function(val){
		layer.alert(val);
	},
	bindFocus : function(id){
		$("#"+id).off("focus");
		$("#"+id).on("focus",function(){
			if(tipsIndex){
				layer.close(tipsIndex);
			}
		})
	},
	bingClosetipsIndex : function(){
		var ids = ["user_name","user_pwd","imgfileUrl"];
		for(var i=0;i<ids.length;i++){
			promotionauth.bindFocus(ids[i]);
		}
	},
	doUpload : function(formId,urlId){
		var from = $("#"+formId);
		var fileUrl = $("#"+urlId).val();
		if(fileUrl.trim() == ""){
			$("#"+urlId).val($("#select_imgurl").html());
		}
		if(!promotionauth.checkImgType(fileUrl)){
			return;
		}
		var formData = new FormData(from[0]);
		$.ajax({
			url:"/personal/promotion/uploadImage",
			type:"post",
			dateType:"json",
			data:formData,
			processData: false,
		    contentType: false,
		    error:function(){
				promotionauth.msg("图片上传服务器错误");
			},
			success:function(data){
				if(data.code == "200"){
					$("#img_url").attr("src",data.url);
					$("#result_img_url").val(data.url);
					$("#select_imgurl").html(fileUrl);
				}else{
					promotionauth.msg(data.message);
				}
			}
		});
	},
	removeValue : function(){
		$("#img_url").attr("src",'');
		$("#result_img_url").val('');
		$("#select_imgurl").html('');
		$("#imgfileUrl").val('');
	},
	isNotNull : function(id){
		var flag = true;
		var obj = $("#"+id);
		var val = obj.val().trim();
		if(val.length < 1){
			tipsIndex = layer.tips("此处不能为空",obj,{tips: 2});
			flag = false;
		}
		return flag;
	},
	// 认证提交
	authSub:function(){
		if(promotionauth.isNotNull("user_name")){
			if($("#user_pwd").is(':visible')){
				if(!promotionauth.isNotNull("user_pwd")){
					return;
				}
			}
			var imgUrl = $("#result_img_url").val();
			if(imgUrl.trim().length < 1){
				tipsIndex = layer.tips("此处不能为空","#imgfileUrl",{tips: 2});
				return;
			}
			var accountType = $("input[type='radio']:checked").val();
			$.ajax({
				url:"/personal/promotion/promotionAauthSub",
				type:"post",
				dataType:"json",
				data:{
					"account":$("#user_name").val(),
					"password":$("#user_pwd").val(),
					"accountType":accountType,
					"image":$("#result_img_url").val(),
					"token":$("#token_id").val()
				},
				error:function(){
					promotionauth.msg("服务器繁忙，请稍后再试！");
				},
				success:function(data){
					if(data.code == "200"){
						promotionauth.msg("认证成功");
						$("#authSubBtn").val("审核中");
						$("#authSubBtn").off("click");
						window.location.href="/personal/promotion/loadPromotionAauth?aNum=6";
					}else{
						promotionauth.msg(data.message);
					}
				}
			});
		}
	},// 类型选择
	selectType : function(type){
		if(type == 1){
			$(".pwdhidden").show();
		}else if(type == 2){
			$(".pwdhidden").hide();
		}
	},
	redioSelct : function(){
		$(".textright :radio").click(function(){
			if($(this).is(':checked')){
				promotionauth.selectType($(this).val());
			}
		});
	},
	selectRedioByType : function(type){
		if(type){
			$("input[type='radio']").each(function(){
				if($(this).val() == type){
					$(this).attr("checked","checked");
				}
			});
		}
	},
	showImg : function(){
		if($('#img_url').attr("src").trim() == ""){
			return;
		}
		$("#img_url").off("click");
		var initwidth=$("#img_url").width();
		var initheight=$("#img_url").height();
		var width = initwidth*2.5+'px';
		var height = initheight*2.5+'px';
		$(".itemImg img").css({
			'width':width,
			'height':height
		});
		layer.open({
		  type: 1,
		  title: false,
		  closeBtn: 0,
		  scrollbar:false,
		  skin: 'layui-layer-nobg', //没有背景色
		  shadeClose: true,
		  area: [width,height],
		  end:function(){
			  $(".itemImg img").css({
					'width':initwidth+"px",
					'height':initheight+"px"
			  });
			  $("#img_url").on('click',function(){
					promotionauth.showImg();
			  });
		  },
		  content: $('.itemImg')
		});
		$('.layui-layer-content').css('overflow','hidden');
	}
}
$("#authSubBtn").on("click",function(){
	promotionauth.authSub();
});
$("#img_url").on('click',function(){
	promotionauth.showImg();
});

</script>

</html>